package com.android.fragmentdemo.adapters
import android.util.Log
import com.android.fragmentdemo.R
import com.android.fragmentdemo.databinding.RvFloatItemLayoutBinding
import com.hengfoxwolf.commonbase.base.adapter.BaseRvAdapter

class FocusFloatRvAdapter() : BaseRvAdapter<String, RvFloatItemLayoutBinding>() {

    override fun getLayoutId(): Int = R.layout.rv_float_item_layout

    override fun bindData(holder: ViewHolder, dataItem: String, position: Int) {

        holder.binding.floatTvContent.text = dataItem
        holder.binding.floatTvContent.setOnFocusChangeListener { target, hasFocus ->
            if (hasFocus) {
                holder.binding.floatTvContent.setBackgroundColor(mContext!!.resources.getColor(R.color.color_DC8717))
            } else {
                holder. binding.floatTvContent.setBackgroundColor(mContext!!.resources.getColor(R.color.color_83CF39))
            }
        }
        Log.d(TAG, "position:${position}")
    }

    override fun listenerWithBinding(binding: RvFloatItemLayoutBinding) {
        super.listenerWithBinding(binding)
        Log.d(TAG, "id:${binding.root.id}")
        binding.floatTvContent.setOnClickListener {
            mOnItemClickListener?.onItemClick(
                binding.root.tag as String,
                binding.root.id,
                binding.floatTvContent.id
            )
        }
    }

    companion object {
        const val TAG = "FloatRvAdapter"
    }
}